var totalnum=0;

var callback=1;
var pageNo=1;
function findMyOrder(){
		$.ajax({
			url:basePath+'/order/findOrder',
			type:'get',
			data:{"pageNo":pageNo,"pageSize":2},
			dataType:'json',
			success:function(data)
			{
				   var count=totalnum;
	    		    totalnum=data.json.data.totalPage;
	    		   if(totalnum!=count)
	    		       initPagination();
				$(".order").empty();
				for(var i=0;i<data.json.data.list.length;i++){
					var state;
					(data.json.data.list[i].ostate==false)?state="未支付":state="已支付";
					
				$(".order").append('  <li > <div class="order_top clear"><img src="'+basePath+'/img/poin.jpg" />'
	                +' <span>'+data.json.data.list[i].gname+'</span> <span class="cost">￥'+data.json.data.list[i].ofee+'</span><span>'+state+'</span> </div>'
	                +'<div class="order_bottom clear"><div class="order_bl">总计：￥<span id='+data.json.data.list[i].oid+'>'+data.json.data.list[i].ofee+'</span>'
	                +' </div>   <div class="order_br"><div class="order_br_t"><input type="checkbox"  onclick="addfee(this,'+data.json.data.list[i].oid+')"/>'
	                +' <label>是否用晚餐</label> </div>  <div><a href="javascript:;"  onclick="submitOrder('+data.json.data.list[i].oid+')"> <input type="button" value="提交订单"> </a>  </div></div></div> </li>');
				}
			},
			error:function()
			{
				alert("500:服务器错误");
			}
		});
	}
function addfee(checkbox,id)
{
	var fee=$("#"+id).text();
	if ( checkbox.checked == true){
	$("#"+id).empty();
    	var num1 = parseFloat(fee);
    	num1+=100;
    	$("#"+id).append(num1);
	}
	else
		{
		$("#"+id).empty();
    	var num1 = parseFloat(fee);
    	num1-=100;
    	$("#"+id).append(num1);
		}
}

function submitOrder(id)
{
	var fee=$("#"+id).text();
	$.ajax({
		url:basePath+'/order/updateFee',
		type:'post',
	    dateType:'json',
	    data:{"orderId":id,"fee":fee},
	    success:function()
	    {
	    	window.location.href=basePath+'/student/pay';
	    },
	    error:function()
	    {
	    	alert("500:服务器错误");
	    }		
	});	
}

function initPagination() {
	//var num_entries = $("#hiddenresult div.result").length;
	// 创建分页
	$("#Pagination").pagination(totalnum, {
		num_edge_entries: 1, //边缘页数
		num_display_entries: 4, //主体页数
		callback: pageselectCallback,
		items_per_page: 1, //每页显示1项
		prev_text: "前一页",
		next_text: "后一页"
	});
 }
function pageselectCallback(page_index, jq){
         page_index+=1;    
         pageNo=page_index;
        	 (callback==1)? callback=0:findMyOrder(); 
		return false;
	}